//
//  QuestDetailsVC.m
//  YZZX
//
//  Created by Easaa on 15/6/11.
//  Copyright (c) 2015年 Easaa. All rights reserved.
//

#import "QuestDetailsVC.h"

@interface QuestDetailsVC ()<HXHttpRequestDelegate>
{
    HXHttpRequest *_httpRequest;
    
}

@end

@implementation QuestDetailsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title =@"详情";
    
    
    NSMutableArray  *arrydata =[[NSMutableArray alloc]init];
    [arrydata addObject:self.id_massge];
    
    
    //列表请求
    NSDictionary* dicParams = [NSDictionary dictionaryWithObjectsAndKeys:
                               [XSZ_UICommon useridChangUaerdfLoginBoolString],    @"user_id",
                               @"1",                    @"site_id",
                               arrydata,                @"ids",
                               nil];
    

    
    if (_httpRequest == nil)
    {
        _httpRequest = [[HXHttpRequest alloc] init];
        _httpRequest.delegate = self;
        
        
        
    }
    [_httpRequest requestForParams:dicParams andMethod:YZ_COUNSEL_CONSULTING_QUERY andTag:1001];
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

}

- (void)creatRequestDataView
{
//    huodong_huida@2x
//    huodong_zhaunjia@2x
//    huodong_yonghu@2x
    
    //专家名字图片
    UIImageView  *imageViewtitle  = [[UIImageView alloc]initWithFrame:CGRectMake(20,6, 15, 15)];
    imageViewtitle.image = [UIImage imageNamed:@"huodong_zhaunjia@2x.png"];
    [self.view addSubview:imageViewtitle];
    
    //专家名字
    UILabel *zhuangjia= [[UILabel alloc] initWithFrame:CGRectMake(40, 0, Dev_ScreenWidth/2-40, 30)];
    zhuangjia.font = [UIFont boldSystemFontOfSize:16];  //UILabel的字体大小
    zhuangjia.numberOfLines = 0;  //必须定义这个属性，否则UILabel不会换行
    //labelTitle.textColor = RGBCOLOR(0, 0, 147);
    zhuangjia.textAlignment = NSTextAlignmentLeft;  //文本对齐方式
//    [zhuangjia setBackgroundColor:[UIColor redColor]];
    zhuangjia.text =self.AdvisoryDataModel.ReceiverName;
    [self.view addSubview:zhuangjia];
    
    
    //专家回答时间
    UILabel *labelTitleTime = [[UILabel alloc] initWithFrame:CGRectMake(Dev_ScreenWidth/2+20, 0, Dev_ScreenWidth/2-30, 30)];
    labelTitleTime.font = [UIFont boldSystemFontOfSize:14];  //UILabel的字体大小
    labelTitleTime.numberOfLines = 0;  //必须定义这个属性，否则UILabel不会换行
    //labelTitle.textColor = RGBCOLOR(0, 0, 147);
    labelTitleTime.textAlignment = NSTextAlignmentRight;  //文本对齐方式
//    [labelTitleTime setBackgroundColor:[UIColor redColor]];
    labelTitleTime.text =self.AdvisoryDataModel.SendTime;
    [self.view addSubview:labelTitleTime];

    
    
    
    //线1
    UIView  *viewlines =[[UIView alloc]initWithFrame:CGRectMake(10, 30, Dev_ScreenWidth-10, 1)];
    viewlines.backgroundColor =[UIColor grayColor];
    [self.view addSubview:viewlines];
    
    
    
    //用户名字图片
    UIImageView  *imageuser  = [[UIImageView alloc]initWithFrame:CGRectMake(20,42, 15, 15)];
    imageuser.image = [UIImage imageNamed:@"huodong_yonghu@2x.png"];
    [self.view addSubview:imageuser];
    
    
    
     //提问标题
    UILabel *labelTitleWenTi = [[UILabel alloc] initWithFrame:CGRectMake(40, 35, Dev_ScreenWidth-50, 30)];
    labelTitleWenTi.font = [UIFont boldSystemFontOfSize:16];  //UILabel的字体大小
    labelTitleWenTi.numberOfLines = 0;  //必须定义这个属性，否则UILabel不会换行
    //labelTitle.textColor = RGBCOLOR(0, 0, 147);
    labelTitleWenTi.textAlignment = NSTextAlignmentLeft;  //文本对齐方式
//    [labelTitleWenTi setBackgroundColor:[UIColor redColor]];
    labelTitleWenTi.text =self.AdvisoryDataModel.Title ;
    [self.view addSubview:labelTitleWenTi];
    
    
   CGFloat  Highes = [self.class heightWithConstraintWidth:Dev_ScreenWidth-50 string:self.AdvisoryDataModel.Content];
    
    //提问内容
    UILabel *labelTitleMassge = [[UILabel alloc] initWithFrame:CGRectMake(40, 70, Dev_ScreenWidth-50, Highes)];
    labelTitleMassge.font = [UIFont boldSystemFontOfSize:14];  //UILabel的字体大小
    labelTitleMassge.numberOfLines = 0;  //必须定义这个属性，否则UILabel不会换行
    labelTitleMassge.textColor = [UIColor grayColor];
    labelTitleMassge.textAlignment = NSTextAlignmentLeft;  //文本对齐方式
//    [labelTitleMassge setBackgroundColor:[UIColor redColor]];
    labelTitleMassge.text =self.AdvisoryDataModel.Content;
    [self.view addSubview:labelTitleMassge];

    
    
    //线2
    UIView  *viewlines0 =[[UIView alloc]initWithFrame:CGRectMake(40, labelTitleMassge.bottom+20-3, Dev_ScreenWidth-40, 1)];
    viewlines0.backgroundColor =[UIColor grayColor];
    [self.view addSubview:viewlines0];
    
    //专家回答标识图片
    UIImageView  *imagebiaoshi  = [[UIImageView alloc]initWithFrame:CGRectMake(20,labelTitleMassge.bottom+28, 15, 15)];
    imagebiaoshi.image = [UIImage imageNamed:@"huodong_huida@2x.png"];
    [self.view addSubview:imagebiaoshi];
    
    if ([self.AdvisoryDataModel.ReplyContent isEqual:[NSNull null]])
    {
        self.AdvisoryDataModel.ReplyContent = @"    等待专家回复...";
    }
    
    CGFloat  HighesMassge = [self.class MassgeheightWithConstraintWidth:Dev_ScreenWidth-50 string:self.AdvisoryDataModel.ReplyContent];
    
    //专家内容
    UILabel *zhuangjiaMassge = [[UILabel alloc] initWithFrame:CGRectMake(40, labelTitleMassge.bottom+25, Dev_ScreenWidth-50, HighesMassge)];
    zhuangjiaMassge.font = [UIFont boldSystemFontOfSize:16];  //UILabel的字体大小
    zhuangjiaMassge.numberOfLines = 0;  //必须定义这个属性，否则UILabel不会换行
    //labelTitle.textColor = RGBCOLOR(0, 0, 147);
    zhuangjiaMassge.textAlignment = NSTextAlignmentLeft;  //文本对齐方式
//    [zhuangjiaMassge setBackgroundColor:[UIColor redColor]];
    zhuangjiaMassge.text =self.AdvisoryDataModel.ReplyContent ;
    [self.view addSubview:zhuangjiaMassge];



}



#pragma mark - HXHttpRequestDelegate  代理

- (void)requestFinished:(NSString *)responseString andStatusCode:(int)statusCode andTag:(NSInteger)tag
{

    [MBProgressHUD hideHUDForView:self.view animated:YES];
    
    NSDictionary *dic = [[NSDictionary alloc]init];
    dic = [JsonUtil jsonToDic:responseString];
    
    if ([dic[@"data"] isEqual:[NSNull null]])
    {
        return;
    }
    
    NSString * strs = dic[@"data"];
    
    NSDictionary *dics =[JsonUtil jsonToDic:strs];
    
    NSArray *arryy =(NSArray *)dics;
    
    NSLog(@"-----------> %@",arryy);
    
    
    
      
    NSDictionary *dicuu = [arryy objectAtIndex:0];
    
   self.AdvisoryDataModel =[[AdvisoryModel alloc]initWithDataManagement:dicuu];
    

    [self creatRequestDataView];
}

- (void)requestFailed:(NSError *)error andTag:(NSInteger)tag
{
    
    
    
    
}



+ (CGFloat)heightWithConstraintWidth:(CGFloat)width string:(NSString *)string
{
    CGSize sizeToFit = [string sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(width, CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping];
    return sizeToFit.height;
}

+ (CGFloat)MassgeheightWithConstraintWidth:(CGFloat)width string:(NSString *)string
{
    CGSize sizeToFit = [string sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:CGSizeMake(width, CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping];
    return sizeToFit.height;
}



@end
